{extend name="layout:base"}

{block name="body"}

{include file="common:nav"}

<div class="container mt-20 bg-fff br-5">
    <div class="row">
        <div class="col-lg-12 mt-10">
            <div class="alert alert-warning">
                <p>微信接口地址：<b>{php}echo rtrim(env('app_url'), '/') . url('wechat/wechat/api'){/php}</b></p>
            </div>
        </div>
        <div class="col-lg-12">
            <h3 class="mb-20">微信基本配置</h3>

            <form action="{:url('setting/postSave')}" method="post">
                {:token()}

                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信AppId</label>
                    <div class="col-lg-4">
                        <input type="text" name="wechat_appid" value="{:config('wefee.wechat_appid')}" class="form-control" placeholder="请输入微信APPID">
                    </div>
                </div>

                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信Secret</label>
                    <div class="col-lg-4">
                        <input type="text" name="wechat_appsecret" value="{:config('wefee.wechat_appsecret')}" class="form-control" placeholder="请输入微信APPSecret">
                    </div>
                </div>

                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信Token</label>
                    <div class="col-lg-4">
                        <div class="input-group">
                            <input type="text" name="wechat_token" value="{:config('wefee.wechat_token')}" class="form-control" placeholder="请输入微信Token">
                            <div class="input-group-addon click-gen-token-button">点击生成</div>
                        </div>
                    </div>
                </div>

                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信AesKey</label>
                    <div class="col-lg-4">
                        <div class="input-group">
                            <input type="text" name="wechat_aeskey" value="{:config('wefee.wechat_aeskey')}" class="form-control" placeholder="请输入微信AesKey">
                            <div class="input-group-addon click-gen-aeskey-button">点击生成</div>
                        </div>
                    </div>
                </div>

                <div class="row mb-10">
                    <div class="col-lg-4 col-lg-offset-3">
                        <button type="submit" class="btn btn-default">
                            <i class="fa fa-check-circle" aria-hidden="true"></i> 确定
                        </button>
                    </div>
                </div>

            </form>


            <h3 class="mb-20">微信支付配置</h3>

            <form action="{:url('setting/postSave')}" method="post">
                {:token()}
                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信支付商户号MchId</label>
                    <div class="col-lg-4">
                        <input type="text" name="wepay_mchid" value="{:config('wefee.wepay_mchid')}" class="form-control" placeholder="请输入微信支付商户号mchid">
                    </div>
                </div>

                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信支付key</label>
                    <div class="col-lg-4">
                        <input type="text" name="wepay_key" value="{:config('wefee.wepay_key')}" class="form-control" placeholder="请输入微信支付key">
                    </div>
                </div>

                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信支付公钥证书路径</label>
                    <div class="col-lg-4">
                        <input type="text" name="wepay_public_pem" value="{:config('wefee.wepay_public_pem')}" class="form-control" placeholder="请输入微信支付公钥证书路径">
                    </div>
                    <div class="col-lg-5">
                        <span class="help-block">请通过FTP工具将证书上传到服务器目录，并在此输入该证书的路径</span>
                    </div>
                </div>

                <div class="row mb-20">
                    <label class="col-lg-3 text-right">微信支付私钥证书</label>
                    <div class="col-lg-4">
                        <input type="text" name="wepay_private_pem" value="{:config('wefee.wepay_private_pem')}" class="form-control" placeholder="请输入微信支付私钥证书">
                    </div>
                    <div class="col-lg-5">
                        <span class="help-block">请通过FTP工具将证书上传到服务器目录，并在此输入该证书的路径</span>
                    </div>
                </div>

                <div class="row mb-20">
                    <div class="col-lg-4 col-lg-offset-3">
                        <button type="submit" class="btn btn-default">
                            <i class="fa fa-check-circle" aria-hidden="true"></i> 确定
                        </button>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>

{include file="common:footer"}

{/block}

{block name="footer"}
<script>
    require(['jquery'], function ($) {
        /**
         *  生成随机字符串
         * */
        var randomStr = function (randomFlag, min, max){
            var str = "",
                    range = min,
                    arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
            if(randomFlag){
                range = Math.round(Math.random() * (max-min)) + min;
            }
            for(var i=0; i<range; i++){
                pos = Math.round(Math.random() * (arr.length-1));
                str += arr[pos];
            }
            return str;
        };

        $('.click-gen-token-button').click(function () {
            $('input[name="wechat_token"]').val(randomStr(false, 32));
        });

        $('.click-gen-aeskey-button').click(function () {
            $('input[name="wechat_aeskey"]').val(randomStr(false, 64));
        });
    });
</script>
{/block}